Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the correct memory for host func #254

Merged
merged 12 commits into from
Aug 10, 2024
Merged

Use the correct memory for host func #254

merged 12 commits into from
Aug 10, 2024

Conversation

yamt
Copy link
Owner

@yamt yamt commented Aug 7, 2024

before this, the single memory was somehow assumed.
after this, the memory exported as "memory" (or the imported memory for dynamic-linking pie executables) is used.

apply the similar to __indirect_function_table as well.

@yamt
Copy link
Owner Author

yamt commented Aug 7, 2024

dyld test failed.

https://github.com/WebAssembly/WASI/blob/main/legacy/application-abi.md says

Regardless of the kind, all modules accessing WASI APIs also export a linear memory with the name memory. Data pointers in WASI API calls are relative to this memory's index space.

but libc.so etc doesn't export "memory".

actually, wasm-ld rejects -shared -export-memory.
https://github.com/llvm/llvm-project/blob/06a808c4f4014edfeb2517bddd0bcb63eb4a260b/lld/wasm/Driver.cpp#L658

similar situation for tables.
https://github.com/llvm/llvm-project/blob/06a808c4f4014edfeb2517bddd0bcb63eb4a260b/lld/wasm/Driver.cpp#L692
https://github.com/llvm/llvm-project/blob/06a808c4f4014edfeb2517bddd0bcb63eb4a260b/lld/wasm/Driver.cpp#L632

@yamt yamt marked this pull request as draft August 7, 2024 17:36
yamt added 10 commits August 9, 2024 00:08
Instead of assuming memory index 0,
look up an export with the name "memory".
to be consistent with cconv_deref_func_ptr
to prepare for other strategies to pick a memory to use.
there are no foreseeable users. let's simplify.
maybe it's a bit clear to do:

```
struct host_instance_using_cconv {
    struct host_instance hi;
    struct meminst *mem;
    struct tableinst *func_table;
}
```

but i didn't bother to do that right now. i might revisit later.

also, do the same for the table as well.

also, make the repl initialize them accordingly.
(only for memory, just because wasi doesn't happen to
use function pointers.)
dyld_func_table is currently unused.
but i added it for consistency.
it would be necessary if an embedder provides host functions
which use function pointers.
i'm not entirely happy with the use of a callback.
i may revisit this later.
@yamt
Copy link
Owner Author

yamt commented Aug 10, 2024

thread_spawn-simple is failing because it doesn't export memory.

@yamt yamt marked this pull request as ready for review August 10, 2024 09:16
@yamt yamt merged commit 3a646f2 into master Aug 10, 2024
144 checks passed
@yamt yamt deleted the wasi-multi-memory branch August 10, 2024 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant